const { SearchProxy } = require('../proxys')
module.exports = class SearchController {
  static async search (ctx) {
    const { limit = 20, offset = 0, keywords } = ctx.query
    if (keywords === '') {
      ctx.status = 400
      ctx.type = 'json'
      ctx.body = {
        code: -1,
        msg: '请输入查询关键字'
      }
      return
    }
    const cookie = ctx.get('Cookie') ? ctx.get('Cookie') : ''
    let result = await SearchProxy.search(limit, offset, keywords, cookie)
    result = JSON.parse(result)
    ctx.status = 200
    ctx.response.type = 'json'
    ctx.response.body = {
      code: 0,
      data: result
    }
  }
}